package com.community.service.page;

import com.community.entity.Announcement;
import com.community.entity.Result;
import com.community.mapper.page.PageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PageService {

    @Autowired
    private PageMapper pageMapper;

    public Result getTop3Announcements() {
        try {
            List<Announcement> announcements = pageMapper.findTop3Announcements();
            if (announcements.isEmpty()) {
                return Result.fail("记录不存在");
            }
            return Result.success(announcements);
        } catch (Exception e) {
            return Result.fail(500, "内部错误");
        }
    }

    public Result getAnnouncementById(String id) {
        try {
            Announcement announcement = pageMapper.findAnnouncementById(id);
            if (announcement == null) {
                return Result.fail("公告不存在");
            }
            return Result.success(announcement);
        } catch (Exception e) {
            return Result.fail(500, "内部错误");
        }
    }
}